/**
 * 与 http://www.aies.cn/ 转换的结果一致 2020-2-21
 * 空间优先，性能比较低
 */
var simplified = require('./simplified-chinese');
var traditional = require('./traditional-chinese');

function change(str, isToSimplify) {
  if (!str) {
    return str;
  }
  var re = '';
  var target, other;
  if (isToSimplify) {
    other = simplified;
    target = traditional;
  } else {
    target = simplified;
    other = traditional;
  }
  for (var i = 0; i < str.length; i++) {
    var theChar = str[i];
    var index = target.indexOf(theChar);
    re += index < 0 ? theChar : other[index];
  }
  return re;
}

module.exports = {
  simplify: function (str) {
    return change(str, true);
  },
  traditionalized: function (str) {
    return change(str);
  }
}